#!/bin/bash

projectPath=$(pwd)
buildPath=$projectPath/build/
configFiles=$projectPath/configs/
cmdPath=$projectPath/cmd

function init() {
  mkdir -p "$buildPath"/configs "$buildPath"/logs "$buildPath"/bin
  cp -r "$configFiles"*.yaml "$buildPath"/configs
  cp -r "$projectPath"/scripts/* "$buildPath"
}

function compile() {
  echo "$1 building"
  cd "$cmdPath"/"$1"/
  GOOS=linux GOARCH=amd64 go build -tags=nomsgpack -ldflags -w -o "$buildPath"/bin
  echo "$1 build ok"
}

function usage() {
  echo "Usage: $0 {api|uc|cat|g8|aviator|avtower|roubig|routower|init|betower|admin}"
  exit 1
}

if [ $# != 1 ]; then
  usage
fi

case "$1" in
    api|uc|cat|g8|aviator|avtower|betower|roubig|routower|admin)
        compile "$1"
        ;;
    init)
      $1
      ;;
    *)
    usage
esac